from pydantic import BaseModel, Field, model_validator, ValidationError
import typing as T


class KnowledgeHeaderDTO(BaseModel):
    """
    知识库的请求头
    """

    knowledgeBaseId: int = Field(description="知识库id")
    userId: int = Field(description="用户id")
    separators: T.Optional[str] = Field(
        default='\n\n', description="文件的分割符"
    )
    chunk_size: T.Optional[int] = Field(
        default=512, description="文件块的大小", gt=16, le=4000
    )
    chunk_overlap: T.Optional[int] = Field(
        default=0, description="文件块的重叠", ge=0, le=2000
    )

    @model_validator(mode="after")
    def check_chunk_size(self):
        if self.chunk_size < self.chunk_overlap:
            raise ValidationError("chunk_size must be greater than chunk_overlap")
        return self
